// pages/institutions/institutions.js
var util = require("../../utils/util.js")
var api = require("../../utils/api.js")
var app = getApp();
var WxParse = require('../../utils/wxParse/wxParse.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        oType: 1,
        cityid: 0,
        page: 1,
        user_map: [],
        cityid: 0,
        province: 1,
        areaid: 0,
        provincelist: {},
        arealist: {},
        organizationType: {},
        priceType: {},
        priceid: 0,
        type: '',
        price_name: '费用类别',
        typeArr: {},
        areaname: '地区',
		picture:{},
    },

    tableCheck: function(e) {
        var that = this
        let id = e.target.id
        that.setData({
            oType: id,
            cityid: id,
        })
    },
    city: function() {
        var that = this
        that.setData({
            cityid: 0,
        })
    },
    provincetap: function(e) {
        this.setData({
            province: e.currentTarget.dataset.id
        })
        this.getarealist()
    },
    citytap: function(e) {
        this.setData({
            areaid: e.currentTarget.dataset.id,
            areaname: e.currentTarget.dataset.name,
        })
    },
    type_idsChange: function(e) {
        this.setData({
            type: e.detail.value.join(','),
            typeArr: e.detail.value
        })
    },
    price_idsChange: function(e) {
        this.setData({
            priceid: e.detail.value,
            price_name: this.data.priceType[e.detail.value]
        })
    },
    allcancel: function() {
        var that = this
        that.setData({
            page: 1,
            type: '',
            priceid: 0,
            cityid: 0,
            areaid: 0,
            price_name: '费用类别',
            areaname: '地区',
            typeArr: {}
        })
        that.getlist()
    },
    confirm: function() {
        this.setData({
            cityid: 0,
            page: 1

        })
        this.getlist()
    },
    institution: function(e) {
        wx.navigateTo({
            url: '../instdetails/instdetails?id=' + e.currentTarget.id
        })
    },
    getarealist: function() {
        let url3 = app.u.HOME_URL + app.u.GET_AREA_LIST
        let data3 = { province: this.data.province }
        api.requestUrl(data3, url3).then(res => {
            if (res.code == 200) {
                this.setData({
                    arealist: res.data
                })
            } else {
                api.showError(res.msg)
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this
        let url2 = app.u.HOME_URL + app.u.GET_ORG_OPTION
        let data2 = {}
        api.requestUrl(data2, url2).then(res => {
            if (res.code == 200) {
                that.setData({
                    organizationType: res.data.organizationType,
                    priceType: res.data.priceType,
                    provincelist: res.data.area
                })
            } else {
                api.showError(res.msg)
            }
        })
        that.getlist()
        this.getarealist()
		var info={}
		var url5 = app.u.HOME_URL + app.u.LOADINSADV
		api.requestUrl(info, url5).then(res => {
              that.setData({
				  picture:res.data.ad
			  })
		})
    },
    getlist: function() {
        let that = this
        let data = {
            page: that.data.page,
            priceid: that.data.priceid,
            type: that.data.type,
            areaid: that.data.areaid,
        }
        let url = app.u.HOME_URL + app.u.INSTITUTIONS
        api.requestUrl(data, url).then(res => {
            if (res.code == 200) {
                that.setData({
                    user_map: res.data
                })
            }
        })
    },
    onReachBottom: function() {
        let that = this
        let page = that.data.page + 1
        that.setData({
            page: page
        })
        let data = {
            page: page,
            priceid: that.data.priceid,
            type: that.data.type,
            areaid: that.data.areaid,
        }
        let url = app.u.HOME_URL + app.u.INSTITUTIONS
        api.requestUrl(data, url).then(res => {
            if (res.code == 200) {
                that.setData({
                    user_map: res.data.concat(that.data.user_map)
                })
            }
        })
    },
    /**
     * 防止穿透
     */
    doNotMove: function() {
        return;
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        wx.showShareMenu({
            withShareTicket: true
        })
    },

})